************************************
******* OPEN DATASET
************************************
use ...

**********************************************
*MODELS 1-6, AGE GROUP 6 EXAMPLE
**********************************************

*********************************************
*VARIABLE DEFINITIONS
*********************************************
quietly {

**DEPENDENT VARIABLE
{
label define educ_level 640"Doctorate program" 620"Licentiate program" 600"Other postgraduate program" 557 "Vocational university program 5yr" 556"General university program 5yr" 555"Non-university Vocational program 5yr" 550"Other post-secondary program 5yr" 547"Vocational university program 4yr" 546"General university program 4yr" 545"non-university vocational program 4yr" 540"other pos secondary program 4yr" 537"Vocational university program 3yr" 536"General university program 3yr" 535"non-university vocational program 3yr" 532"More than 120 vocat credits, no degree" 530"other pos secondary program 3yr" 527"Vocational university program 2yr" 526"General university program 2yr" 525"non-university vocational program 2yr" 522"B/w 80-120 vocat credits" 520"other pos secondary program 2yr" 417"Vocational university program <2yr" 415"non-university vocational program <2yr" 413"Upper secondary supplementary program" 412"20 credits in one subject" 410"other secondary program <2 yr" 337"Vocational program 3yrs" 336"Theoretical program for higher studies 3yrs" 333"vocational program, incomplete 3yrs" 332"Theoretical program, incomplete 3yrs" 330"Other upper secondary program 3yrs" 327"Vocational program, 2yrs" 326"Theoretical program for higher studies 2yrs" 323"vocational program, incomplete 2yrs" 322"Theoretical program, incomplete 2yrs" 320"Other upper secondary program 2yrs" 317"Vocational program, <2yrs" 316"Theoretical program for higher studies <2yrs" 313"vocational program, incomplete <2yrs" 312"Theoretical program, incomplete <2yrs" 310"Other upper secondary program <2yrs" 206"Compulsory school, 7-9yrs" 204"lower secondary school" 200"Other primary and lower school"  106"Elementary school" 102"Compulsory  school, 1-6" 100"Other primary and lower sec education", modify
label values educ_level educ_level
}

gen uniedu = 0 if educ_level !=. & (agedeath > 40 | agedeath ==.)
replace uniedu = 1 if educ_level > 530  & educ_level !=. & (agedeath > 40 | agedeath ==.)

**CLASS ORIGIN AND OTHER INDIVIDUAL VARIABLES

*Class origin
drop childses
gen childses = 1 if (HF_HC5 == 1|HF_HC5 ==2) & HF_HC5 !=.
replace childses = 2 if HF_HC5 == 3 & HF_HC5 !=.
replace childses = 3 if (HF_HC5 == 4|HF_HC5 == 5|HF_HC5 ==6) & HF_HC5 !=.
replace childses = 4 if HF_HC5 == 7 & HF_HC5 !=.
tab Sc5 if childses !=4 & childses !=. & age == 40 & Sex2 !=.

*Household size
drop HousHoldSize
gen HousHoldSize = HouseholdSize5

*Presence of mother (yes = 1, no = 0)
drop MPR
gen MPR = Mpr5

*Birth year
*(variable: BirthYear)

**NEIGHBORHOOD CLASS VARIABLE

*Neighborhood class
drop catW
gen catW = 2 if nearHFHC1_5 !=.
replace catW = 3 if nearHFHC1_5 < 0.25 & nearHFHC1_5 !=. & nearHFHC3_5 >= 0.5
replace catW = 1 if nearHFHC1_5 >= 0.5 & nearHFHC1_5 !=. & nearHFHC3_5 < 0.25

**SOCIAL ENVIRONMENT VARIABLES

*Estimated elementary school district
drop SchoolD
gen SchoolD = 1 if Sc5 == "Albanoskolan" & Sc5 != " "
replace SchoolD = 2 if Sc5 == "Borstaskolan" & Sc5 != " "
replace SchoolD = 3 if Sc5 == "GustavAdolf" & Sc5 != " "
replace SchoolD = 4 if Sc5 == "Tuppaskolan" & Sc5 != " "
replace SchoolD = 5 if Sc5 == "Varnaskolan" & Sc5 != " "

*Residential mobility
drop stayer
gen stayer = 2 if Age5Address !=.
replace stayer = 1 if Age5Address == Age2Address & Age5Address !=.

*Local born
*(variable: Local)

*Distance to secondary and high school
drop DammCat
gen DammCat = 1 if distDammSch5 < 250 & distDammSch5 !=.
replace DammCat = 2 if distDammSch5 >= 250 & distDammSch5 < 500  & distDammSch5 !=.
replace DammCat = 3 if distDammSch5 >= 500 & distDammSch5 !=.
drop DammQile
egen DammQile = xtile(distDammSch5) if age ==40 & distDammSch5 !=. , by(year) n(3)

*GW sex composition
drop NearFemale
gen NearFemale = nearFemale_5

*GW share of neighbors with missing mother
drop NearMomNo
gen NearMomNo = nearMomNo_5

**PHYSICAL ENVIRONMENT VARIABLES

*Population density
replace PopWithin50mn = (PopWithin50m5 + AddressPop5 - HouseholdSize5)
replace PopWithin50mn = 0 if PopWithin50mn <0
replace PopWithin50mn = log(PopWithin50mn)

*Building type
drop HouseCat
gen HouseCat = 1 if (buildtype5 == "Apartments" | buildtype5 == "Other") & buildtype5 !=" "
replace HouseCat = 2 if (buildtype5 == "Par-Radhus" | buildtype5 == "SingleHouse") & buildtype5 != " "

*Proximity to major road
drop streetcat
gen streetcat = 2 if dStreetB5 < 100 & dStreetB5 !=.
replace streetcat = 1 if dStreetB5 >= 100 & dStreetB5 !=.

*Road density
drop roadskm
gen roadskm = roads50m5/100 if roads50m5 !=.
}

*********************************************
*MODEL 1-6 ESTIMATIONS
*********************************************
quietly{
**MODEL 1

*Girls
logit uniedu BirthYear ib3.childses i.Mpr5 HousHoldSize if childses !=. & age ==40 & Sex2 == 1 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace modelno = 1
replace agemod = 5
replace modelsex = 1
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses modelno agemod modelsex using"\\..M1GAge5.csv" if bchildses !=. in 1, replace
estimates store A5F_Mod1

*Boys
logit uniedu BirthYear ib3.childses i.Mpr5 HousHoldSize if childses !=. & age ==40 & Sex2 == 2 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace modelno = 1
replace agemod = 5
replace modelsex = 2
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses modelno agemod modelsex using"\\..M1BAge5.csv" if bchildses !=. in 1, replace
estimates store A5M_Mod1

**MODEL 2

*Girls
logit uniedu BirthYear ib3.catW i.Mpr5 HousHoldSize if catW !=. & age ==40 & Sex2 == 1 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bcatW= a[1,3]
replace pvcatW = a[4,3]
replace llcatW = a[5,3]
replace ulcatW = a[6,3]
replace modelno = 2
replace agemod = 5
replace modelsex = 1
matrix drop a
export delimited bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M2GAge5.csv" if bcatW !=. in 1, replace
estimates store A5F_Mod2

*Boys
logit uniedu BirthYear ib3.catW i.Mpr5 HousHoldSize if catW !=. & age ==40 & Sex2 == 2, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bcatW= a[1,3]
replace pvcatW = a[4,3]
replace llcatW = a[5,3]
replace ulcatW = a[6,3]
replace modelno = 2
replace agemod = 5
replace modelsex = 2
matrix drop a
export delimited bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M2BAge5.csv" if bcatW !=. in 1, replace
estimates store A5M_Mod2

** MODEL 3

*Girls
logit uniedu BirthYear ib3.childses ib3.catW i.Mpr5 HousHoldSize if catW !=. & age ==40 & Sex2 == 1 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace bcatW= a[1,6]
replace pvcatW = a[4,6]
replace llcatW = a[5,6]
replace ulcatW = a[6,6]
replace modelno = 3
replace agemod = 5
replace modelsex = 1
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M3GAge5.csv" if bcatW !=. in 1, replace
estimates store A5F_Mod3

*Boys
logit uniedu BirthYear ib3.childses ib3.catW i.Mpr5 HousHoldSize if catW !=. & age ==40 & Sex2 == 2 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace bcatW= a[1,6]
replace pvcatW = a[4,6]
replace llcatW = a[5,6]
replace ulcatW = a[6,6]
replace modelno = 3
replace agemod = 5
replace modelsex = 2
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M3BAge5.csv" if bcatW !=. in 1, replace
estimates store A5M_Mod3

*MODEL 4

*Girls
logit uniedu BirthYear ib3.childses ib3.catW i.DammQile ib1.SchoolD ib2.stayer i.Local NearFemale NearMomNo i.Mpr5 HousHoldSize if catW !=. & age ==40 & Sex2 == 1 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace bcatW= a[1,6]
replace pvcatW = a[4,6]
replace llcatW = a[5,6]
replace ulcatW = a[6,6]
replace modelno = 4
replace agemod = 5
replace modelsex = 1
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M4GAge5.csv" if bcatW !=. in 1, replace
estimates store A5F_Mod4

*Boys
logit uniedu BirthYear ib3.childses ib3.catW i.DammQile ib1.SchoolD ib2.stayer i.Local NearFemale NearMomNo i.Mpr5 HousHoldSize if catW !=. & age ==40 & Sex2 == 2 & childses != 4, or
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace bcatW= a[1,6]
replace pvcatW = a[4,6]
replace llcatW = a[5,6]
replace ulcatW = a[6,6]
replace modelno = 4
replace agemod = 5
replace modelsex = 2
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M4BAge5.csv" if bcatW !=. in 1, replace
estimates store A5M_Mod4

** MODEL 5

*Girls
logit uniedu BirthYear ib3.childses ib3.catW i.DammQile ib1.SchoolD ib2.stayer i.Local NearFemale NearMomNo PopWithin50mn roadskm i.streetcat i.HouseCat i.MPR HousHoldSize if catW !=. & age ==40 & Sex2 == 1 & childses != 4, or
*When estimating Moran's I (SI Appendix, Table 3)
predict double residFA5 if e(sample), residuals
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace bcatW= a[1,6]
replace pvcatW = a[4,6]
replace llcatW = a[5,6]
replace ulcatW = a[6,6]
replace modelno = 5
replace agemod = 5
replace modelsex = 1
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M5GAge5.csv" if bcatW !=. in 1, replace
estimates store A5F_Mod5

*Boys
logit uniedu BirthYear ib3.childses ib3.catW i.DammQile ib1.SchoolD ib2.stayer i.Local NearFemale NearMomNo PopWithin50mn roadskm i.streetcat i.HouseCat i.MPR HousHoldSize if catW !=. & age ==40 & Sex2 == 2 & childses != 4, or
*When estimating Moran's I (SI Appendix, Table 3)
predict double residMA5 if e(sample), residuals
*Exporting estimates for Figure 4
matrix a = r(table)
replace bchildses = a[1,3]
replace pvchildses = a[4,3]
replace llchildses = a[5,3]
replace ulchildses = a[6,3]
replace bcatW= a[1,6]
replace pvcatW = a[4,6]
replace llcatW = a[5,6]
replace ulcatW = a[6,6]
replace modelno = 5
replace agemod = 5
replace modelsex = 2
matrix drop a
export delimited bchildses pvchildses llchildses ulchildses bcatW pvcatW llcatW ulcatW modelno agemod modelsex using"\\..M5BAge5.csv" if bcatW !=. in 1, replace
estimates store A5M_Mod5


*MODEL 6

*Girls
*# instead of ## for Figure 5
logit uniedu BirthYear ib3.childses##ib3.catW i.DammQile ib1.SchoolD ib2.stayer i.Local NearFemale NearMomNo PopWithin50mn roadskm i.streetcat i.HouseCat i.MPR HousHoldSize if catW !=. & age ==40 & Sex2 == 1 & childses != 4, or
estimates store A5F_Mod6

*Boys
*# instead of ## for Figure 5
logit uniedu BirthYear ib3.childses##ib3.catW i.DammQile ib1.SchoolD ib2.stayer i.Local NearFemale NearMomNo PopWithin50mn roadskm i.streetcat i.HouseCat i.MPR HousHoldSize if catW !=. & age ==40 & Sex2 == 2 & childses != 4, or
estimates store A5M_Mod6

}


*********************************************
*FIGURE 4 AND 5
*********************************************

*FIGURE 4 (MODELS 1-5, USING )

*Import multiple csv-files with model informations (used for Figure 5)
cd "\..\Figure5"
clear
local statafiles : dir . files "*.csv"

foreach file of local statafiles{
preserve
insheet using `file', names clear
save temp, replace
restore
append using temp, force
}

*For overlapping symbols
*drop x
clonevar x = agemod 
replace x = cond(modelno == 1, x - 0.6, cond(modelno == 2, x - 0.3, cond(modelno == 3, x - 0, cond(modelno == 4, x + 0.3, cond(modelno == 5, x + 0.6, x + 0)))))

*Girls, Class origin (Figure 5A)
twoway (line bchildses x if modelno == 1 & modelsex == 2, lpattern(dash) lwidth(medthin) lcolor(black)) (line bchildses x if modelno == 3 & modelsex == 2, lpattern(dash) lwidth(medthin) lcolor("0 255 0")) (line bchildses x if modelno == 4 & modelsex == 2, lpattern(dash) lcolor(cyan) lwidth(medthin)) (connected bchildses x if modelno == 5 & modelsex == 2, lpattern(dash) lcolor(blue) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 1 & modelsex == 2, lcolor(black) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 3 & modelsex == 2, lcolor(black) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 4 & modelsex == 2, lcolor(black) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 5 & modelsex == 2, lcolor(black) lwidth(medthin)) (scatter bchildses x if modelno == 1 & modelsex == 2, msymbol(S) msize(medlarge) mfcolor(white) mcolor(black)) (scatter bchildses x if modelno == 3 & modelsex == 2, msymbol(O)  msize(medlarge) mfcolor("0 255 0") mcolor("0 255 0")) (scatter bchildses x if modelno == 4 & modelsex == 2, msymbol(D) mfcolor(cyan) msize(medlarge) mcolor(cyan)) (scatter bchildses x if modelno == 5 & modelsex == 2, msymbol(S) mfcolor(blue) msize(medlarge) mcolor(blue)) , legend( col(2) order(9 "M1 (Class origin)" 10 "M3 (M1 + M2)" 11 "M4 (M3 + Social env.))" 12 "M5 (M4 + Physical env.)"))  ytitle(OR and 95% CI) yline(1, lpattern(dash) lcolor(black) lwidth(medthin)) yscale(log) yscale(range(0.75 6.04)) ylabel(0.7 1 1.5 2.5 4 6, angle(horizontal) labsize(medlarge) nogrid nogextend) xlabel(2 5 8 11 14 17 ,labsize(medlarge)) ymtick(0.8 0.9 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.5 4 4.5 5 5.5 6, tposition(inside)) xmtick(2 5 8 11 14 17, tposition(inside)) xtitle(Age groups) graphregion(color(white) ) plotregion(lcolor(black) lwidth(medthin)) saving(ClassOriginMale, replace)

*Boys, Class origin (Figure 5B)
twoway (line bchildses x if modelno == 1 & modelsex == 1, lpattern(dash) lwidth(medthin) lcolor(black)) (line bchildses x if modelno == 3 & modelsex == 1, lpattern(dash) lwidth(medthin) lcolor("0 255 0")) (line bchildses x if modelno == 4 & modelsex == 1, lpattern(dash) lcolor(cyan) lwidth(medthin)) (connected bchildses x if modelno == 5 & modelsex == 1, lpattern(dash) lcolor(blue) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 1 & modelsex == 1, lcolor(black) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 3 & modelsex == 1, lcolor(black) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 4 & modelsex == 1, lcolor(black) lwidth(medthin)) (rspike llchildses ulchildses x if modelno == 5 & modelsex == 1, lcolor(black) lwidth(medthin)) (scatter bchildses x if modelno == 1 & modelsex == 1, msymbol(S) msize(medlarge) mfcolor(white) mcolor(black)) (scatter bchildses x if modelno == 3 & modelsex == 1, msymbol(O)  msize(medlarge) mfcolor("0 255 0") mcolor("0 255 0")) (scatter bchildses x if modelno == 4 & modelsex == 1, msymbol(D) mfcolor(cyan) msize(medlarge) mcolor(cyan)) (scatter bchildses x if modelno == 5 & modelsex == 1, msymbol(S) mfcolor(blue) msize(medlarge) mcolor(blue)) , legend( col(2) order(9 "M1 (Class origin)" 10 "M3 (M1 + M2)" 11 "M4 (M3 + Social env.))" 12 "M5 (M4 + Physical env.)"))  ytitle(OR and 95% CI) yline(1, lpattern(dash) lcolor(black) lwidth(medthin)) yscale(log) yscale(range(0.75 6.04)) ylabel(0.7 1 1.5 2.5 4 6, angle(horizontal) labsize(medlarge) nogrid nogextend) xlabel(2 5 8 11 14 17 ,labsize(medlarge)) ymtick(0.8 0.9 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.5 4 4.5 5 5.5 6, tposition(inside)) xmtick(2 5 8 11 14 17, tposition(inside)) xtitle(Age groups) graphregion(color(white) ) plotregion(lcolor(black) lwidth(medthin)) saving(ClassOriginFemale, replace)

*Girls, Neighborhood class (Figure 5C)
twoway (line bcatw x if modelno == 2 & modelsex == 1, lpattern(dash) lwidth(medthin) lcolor(black)) (line bcatw x if modelno == 3 & modelsex == 1, lpattern(dash) lwidth(medthin) lcolor("0 255 0")) (line bcatw x if modelno == 4 & modelsex == 1, lpattern(dash) lcolor(cyan) lwidth(medthin)) (connected bcatw x if modelno == 5 & modelsex == 1, lpattern(dash) lcolor(blue) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 2 & modelsex == 1, lcolor(black) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 3 & modelsex == 1, lcolor(black) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 4 & modelsex == 1, lcolor(black) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 5 & modelsex == 1, lcolor(black) lwidth(medthin)) (scatter bcatw x if modelno == 2 & modelsex == 1, msymbol(D) msize(medlarge) mfcolor(white) mcolor(black)) (scatter bcatw x if modelno == 3 & modelsex == 1, msymbol(O)  msize(medlarge) mfcolor("0 255 0") mcolor("0 255 0")) (scatter bcatw x if modelno == 4 & modelsex == 1, msymbol(D) mfcolor(cyan) msize(medlarge) mcolor(cyan)) (scatter bcatw x if modelno == 5 & modelsex == 1, msymbol(S) mfcolor(blue) msize(medlarge) mcolor(blue)) , legend( col(2) order(9 "M2 (Neigh. class)" 10 "M3 (M1 + M2)" 11 "M4 (M3 + Social env.))" 12 "M5 (M4 + Physical env.)")) ytitle(OR and 95% CI) yline(1, lpattern(dash) lcolor(black) lwidth(medthin)) yscale(log) yscale(range(0.75 6.04)) ylabel(0.7 1 1.5 2.5 4 6, angle(horizontal) labsize(medlarge) nogrid nogextend) xlabel(2 5 8 11 14 17 ,labsize(medlarge)) ymtick(0.8 0.9 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.5 4 4.5 5 5.5 6, tposition(inside)) xmtick(2 5 8 11 14 17, tposition(inside)) xtitle(Age groups) graphregion(color(white) ) plotregion(lcolor(black) lwidth(medthin)) saving(NeighClassFemale, replace)

*Boys, Neighborhood class (Figure 5D)
twoway (line bcatw x if modelno == 2 & modelsex == 2, lpattern(dash) lwidth(medthin) lcolor(black)) (line bcatw x if modelno == 3 & modelsex == 2, lpattern(dash) lwidth(medthin) lcolor("0 255 0")) (line bcatw x if modelno == 4 & modelsex == 2, lpattern(dash) lcolor(cyan) lwidth(medthin)) (connected bcatw x if modelno == 5 & modelsex == 2, lpattern(dash) lcolor(blue) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 2 & modelsex == 2, lcolor(black) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 3 & modelsex == 2, lcolor(black) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 4 & modelsex == 2, lcolor(black) lwidth(medthin)) (rspike llcatw ulcatw x if modelno == 5 & modelsex == 2, lcolor(black) lwidth(medthin)) (scatter bcatw x if modelno == 2 & modelsex == 2, msymbol(D) msize(medlarge) mfcolor(white) mcolor(black)) (scatter bcatw x if modelno == 3 & modelsex == 2, msymbol(O)  msize(medlarge) mfcolor("0 255 0") mcolor("0 255 0")) (scatter bcatw x if modelno == 4 & modelsex == 2, msymbol(D) mfcolor(cyan) msize(medlarge) mcolor(cyan)) (scatter bcatw x if modelno == 5 & modelsex == 2, msymbol(S) mfcolor(blue) msize(medlarge) mcolor(blue)) , legend( col(2) order(9 "M2 (Neigh. class)" 10 "M3 (M1 + M2)" 11 "M4 (M3 + Social env.))" 12 "M5 (M4 + Physical env.)")) ytitle(OR and 95% CI) yline(1, lpattern(dash) lcolor(black) lwidth(medthin)) yscale(log) yscale(range(0.75 6.04)) ylabel(0.7 1 1.5 2.5 4 6, angle(horizontal) labsize(medlarge) nogrid nogextend) xlabel(2 5 8 11 14 17 ,labsize(medlarge)) ymtick(0.8 0.9 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.5 4 4.5 5 5.5 6, tposition(inside)) xmtick(2 5 8 11 14 17, tposition(inside)) xtitle(Age groups) graphregion(color(white) ) plotregion(lcolor(black) lwidth(medthin)) saving(NeighClassMale, replace)

gr combine ClassOriginFemale.gph ClassOriginMale.gph NeighClassFemale.gph  NeighClassMale.gph 


*FIGURE 5 (MODEL 6 using Coefplot)

*Girls, Figure 5A
coefplot (A2F_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A2F_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A2F_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A2F_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A2F_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A2F_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A2F_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A2F_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 2) ||(A5F_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A5F_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A5F_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A5F_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A5F_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A5F_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A5F_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A5F_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 5) ||(A8F_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A8F_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A8F_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A8F_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A8F_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A8F_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A8F_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A8F_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 8) ||(A11F_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A11F_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A11F_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A11F_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A11F_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A11F_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A11F_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A11F_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 11) || (A14F_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A14F_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A14F_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A14F_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A14F_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A14F_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A14F_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A14F_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 14) || (A17F_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S))  (A17F_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A17F_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A17F_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A17F_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A17F_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A17F_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A17F_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 17) ||, groups(?.childses#?.catW = "{bf:Class origin (C) # Neigh. class (N)}") coeflabels(1.childses#1.catW = "High C - High N" 1.childses#2.catW = "High C - Mid N" 1.childses#3.catW = "High C - Low N" 2.childses#1.catW = "Mid C - High N" 2.childses#2.catW = "Mid C - Mid N" 2.childses#3.catW = "Mid C - Low N" 3.childses#1.catW = "Low C - High N" 3.childses#2.catW = "Low C - Mid N") xline(1, lpattern(dash) lcolor(black) lwidth(thin)) byopts()  grid(glpattern(blank)) eform xscale(log) lcolor(black) ciopts(lwidth(thin) lcolor(black)) graphregion(color(white) ) plotregion(lcolor(black) margin(b+1.5 t+1.5) lwidth(medthin)) omitted baselevels xlabel(0.3 0.5 1 2 5 10 20) xscale(range(0.3 20)) 
graph export "\\..Figure5A.pdf", as(pdf) name("Graph")

*Boys, Figure 5B
coefplot (A2M_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A2M_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A2M_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A2M_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A2M_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A2M_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A2M_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A2M_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 2) ||(A5M_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A5M_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A5M_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A5M_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A5M_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A5M_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A5M_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A5M_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 5) ||(A8M_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A8M_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A8M_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A8M_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A8M_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A8M_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A8M_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A8M_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 8) ||(A11M_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A11M_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A11M_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A11M_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A11M_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A11M_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A11M_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A11M_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 11) || (A14M_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S)) (A14M_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A14M_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A14M_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A14M_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A14M_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A14M_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A14M_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 14) || (A17M_Mod6, keep(1.childses#1.catW) mfcolor(blue) mlcolor(blue) msymbol(S))  (A17M_Mod6, keep(1.childses#2.catW) mfcolor(blue) mlcolor(blue) msymbol(D)) (A17M_Mod6, keep(1.childses#3.catW) mfcolor(blue) mlcolor(blue) msymbol(O)) (A17M_Mod6, keep(2.childses#1.catW) mfcolor(white) mlcolor(black) msymbol(S)) (A17M_Mod6, keep(2.childses#2.catW) mfcolor(white) mlcolor(black) msymbol(D)) (A17M_Mod6, keep(2.childses#3.catW) mfcolor(white) mlcolor(black) msymbol(O)) (A17M_Mod6, keep(3.childses#1.catW) mfcolor(red) mlcolor(red) msymbol(S)) (A17M_Mod6, keep(3.childses#2.catW) mfcolor(red) mlcolor(red) msymbol(D)), bylabel(Ages 17) ||, groups(?.childses#?.catW = "{bf:Class origin (C) # Neigh. class (N)}") coeflabels(1.childses#1.catW = "High C - High N" 1.childses#2.catW = "High C - Mid N" 1.childses#3.catW = "High C - Low N" 2.childses#1.catW = "Mid C - High N" 2.childses#2.catW = "Mid C - Mid N" 2.childses#3.catW = "Mid C - Low N" 3.childses#1.catW = "Low C - High N" 3.childses#2.catW = "Low C - Mid N") xline(1, lpattern(dash) lcolor(black) lwidth(thin)) byopts()  grid(glpattern(blank)) eform xscale(log) lcolor(black) ciopts(lwidth(thin) lcolor(black)) graphregion(color(white) ) plotregion(lcolor(black) margin(b+1.5 t+1.5) lwidth(medthin)) omitted baselevels xlabel(0.3 0.5 1 2 5 10 20) xscale(range(0.3 20)) 
graph export "\\..Figure5B.pdf", as(pdf) name("Graph")